package com.javasm.crm.service.marketingActivity.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.entity.marketingActivity.Promotion;
import com.javasm.crm.domin.entity.marketingActivity.clinetClaim.PromotionFindClaim;
import com.javasm.crm.mapper.marketingActivity.PromotionMapper;
import com.javasm.crm.service.marketingActivity.PromotionService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author：llyp
 * @Version：1.0
 * @Date：2021/7/12-11:54
 * @Since:jdk1.8
 * @Description:TODO
 */
@Service
@Transactional
public class PromotionServiceImpl extends ServiceImpl<PromotionMapper,Promotion> implements PromotionService {

    @Autowired
    private PromotionMapper promotionMapper;

    @Override
    public PageResult<Promotion> ConditionFindPage(PromotionFindClaim pfc) {
        //分页信息
        Page page = new Page<>(pfc.getCurrent(),pfc.getSize());
        //sql条件
        QueryWrapper queryWrapper = new QueryWrapper();

        if (pfc.getPromotionId() !=null){
            queryWrapper.eq("promotion_Id",pfc.getPromotionId());
        }
        if (StringUtils.hasLength(pfc.getPromotionName())){  //名字
            queryWrapper.like("promotion_Name",pfc.getPromotionName());
        }
        if (pfc.getPromotionStarttime()!=null){  //开始时间
            queryWrapper.eq("Promotion_Starttime",pfc.getPromotionStarttime());
        }
        if (pfc.getPromotionApprovalstatus()!=null){
            queryWrapper.eq("Promotion_Approvalstatus",pfc.getPromotionStarttime());
        }

        //查询
        Page<Promotion> promotionPage = promotionMapper.selectPage(page, queryWrapper);
        //数据信息
        List<Promotion> records  = promotionPage.getRecords();
        //分页信息
        long total = promotionPage.getTotal();

        return new PageResult<Promotion>(total,records);
    }

}
